//
//  ChangeLoginPSWViewController.m
//  PPDL
//
//  Created by 王洋 on 2019/7/24.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "ChangeLoginPSWViewController.h"

@interface ChangeLoginPSWViewController ()

//旧密码
@property (weak, nonatomic) IBOutlet UITextField *oldPswTF;
//新密码
@property (weak, nonatomic) IBOutlet UITextField *latestPswTF;
//确认新密码
@property (weak, nonatomic) IBOutlet UITextField *sureLatestPswTF;


@end

@implementation ChangeLoginPSWViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"修改登录密码";
}

- (IBAction)request_ChangeLoginPsw:(id)sender {
    
    if (!self.oldPswTF.text.length) {
        [self alert:@"请输入旧密码"];
    } else {
        
        if (![self.latestPswTF.text isEqualToString:self.sureLatestPswTF.text]) {
            
            [self alert:@"两次输入密码不一致"];
        } else {
            
            [self request_ChangePswLogin];
        }
    }

}


- (void)request_ChangePswLogin {
    
    NSDictionary *dic = @{}.mutableCopy;
    [dic setValue:self.oldPswTF.text forKey:@"oldPwd"];
    [dic setValue:self.latestPswTF.text forKey:@"pwd"];
    [dic setValue:self.sureLatestPswTF.text forKey:@"pwd1"];
    
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,TT_MEMBER_CHANGE_PSW];
    
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        if ([data isKindOfClass:[NSDictionary class]]) {
            
            NSString * code = [data valueForKey:@"code"];
            if ([code isEqualToString:@"200"]) {
                [SVProgressHUD showSuccessWithStatus:[data valueForKey:@"msg"]];
                [SVProgressHUD dismissWithDelay:1];
                
                [[TTUserModel sharedObject].userModelDefault setValue:self.sureLatestPswTF.text forKey:@"PP_user_password"];
                
                [self.navigationController popToRootViewControllerAnimated:YES];
                
            } else {
                
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"msg"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        } else {
            
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {
        
    }];
    
}
@end
